[assembly: WebActivator.PreApplicationStartMethod(typeof(dai_hoc_tuong_lai.App_Start.NinjectWebCommon), "Start")]
[assembly: WebActivator.ApplicationShutdownMethodAttribute(typeof(dai_hoc_tuong_lai.App_Start.NinjectWebCommon), "Stop")]

namespace dai_hoc_tuong_lai.App_Start
{
    using System;
    using System.Web;

    using Microsoft.Web.Infrastructure.DynamicModuleHelper;

    using Ninject;
    using Ninject.Web.Common;
    using System.Web.Mvc;
    using Ninject.Web.Mvc;
    using Dhtl.Service.IService;
    using Dhtl.Service.Service;
    using Dhtl.Service.Export;

    public static class NinjectWebCommon 
    {
        private static readonly Bootstrapper bootstrapper = new Bootstrapper();

        /// <summary>
        /// Starts the application
        /// </summary>
        public static void Start() 
        {
            DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule));
            DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule));
            bootstrapper.Initialize(CreateKernel);
        }
        
        /// <summary>
        /// Stops the application.
        /// </summary>
        public static void Stop()
        {
            bootstrapper.ShutDown();
        }
        
        /// <summary>
        /// Creates the kernel that will manage your application.
        /// </summary>
        /// <returns>The created kernel.</returns>
        private static IKernel CreateKernel()
        {
            var kernel = new StandardKernel();
            kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel);
            kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();
            
            RegisterServices(kernel);
            return kernel;
        }

        /// <summary>
        /// Load your modules or register your services here!
        /// </summary>
        /// <param name="kernel">The kernel.</param>
        private static void RegisterServices(IKernel kernel)
        {

            kernel.Bind<IAlbum>().To<Service_Album>();
            kernel.Bind<ICateAlbum>().To<Service_CateAlbum>();
            kernel.Bind<ICateNganhHoc>().To<Service_CateNganhHoc>();
            kernel.Bind<INganhHoc>().To<Service_NganhHoc>();
            kernel.Bind<INews>().To<Service_News>();
            kernel.Bind<ISettingPage>().To<Service_SettingPage>();
            kernel.Bind<ITopic>().To<Service_Topic>();
            kernel.Bind<IEmailDangky>().To<Service_EmailDangky>();
            kernel.Bind<IEmailSystem>().To<Service_EmailSystem>();
            kernel.Bind<IRoles>().To<Service_Roles>();
            kernel.Bind<IUser>().To<Service_User>();
            kernel.Bind<IUserInRoles>().To<Service_UserInRoles>();
            kernel.Bind<IExport>().To<Service_Export>();
            kernel.Bind<IContact>().To<Service_Contact>();
            kernel.Bind<IThongbao>().To<Service_Thongbao>();
            kernel.Bind<IVanBan>().To<Service_Vanban>();
            kernel.Bind<ITongquang>().To<Service_tongquang>();
            kernel.Bind<IVanphongdichvu>().To<Service_Vanphongdichvu>();
            kernel.Bind<IThongtintuyensinh>().To<Service_thongtintuyensinh>();


            DependencyResolver.SetResolver(new NinjectDependencyResolver(kernel));

        }        
    }
}
